﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using EnvDTE80;
using Microsoft.VisualStudio.CommandBars;
using EnvDTE;

namespace LazyPlugins.DeclarativeAddinCreator
{
    public static class AddinRegistry
    {

        static readonly Dictionary<string, AddinActionBase> map = new Dictionary<string, AddinActionBase>();

        public static void SetRelatedAction(Type actionType, CommandBarButton button, Command mainCommand, AddIn addinInstance, DTE2 appObj)
        {
            var buttonBase = (AddinActionBase) Activator.CreateInstance(actionType);
            buttonBase.RelatedButton = button;
            buttonBase.AddinInstance = addinInstance;
            buttonBase.ApplicationObject = appObj;

            map[mainCommand.Name] = buttonBase;
        }

        public static AddinActionBase GetActionByName(string commandName)
        {
            return map[commandName];
        }

        public static string GetIconsDirectory()
        {
            string myDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            return myDir+"\\icons";
        }
    }
}
